//返回值为需不需要关闭窗口
function yesOperator() {
    var retValue = addData();
    return retValue;
}

function updateLoad() {
    var params = $$.getQueryString();
    $$.ajax({
        url: "/rest/IotCalcfDirectionBusiness/query",
        data: {
            id: params.rowId
        },
        success: function (data) {
            $("#b_id").val(data.id);
            $("#b_ttable").val(data.ttable);

            $("#b_tcode").val(data.tcode);

            $("#b_stable").val(data.stable);

            $("#b_scode").val(data.scode);

            $("#b_calcStart").val(data.calcStart);

            $("#b_calcEnd").val(data.calcEnd);

            $("#b_status").val(data.status);

            $("#b_rowSort").val(data.rowSort);

            $("#b_remarks").val(data.remarks);


            var status = data.status;

            $("input[name^='b_status_']").each(function () {

                if ($(this).val() == status) {

                    this.checked = 'checked';

                }

            });


            $("#b_calcfCodeOld").val(data.calcfCode);


        }
    });


}

function validForm() {
    return $('#theform').valid();


    /*
    //判断编码唯一性
    if(!notNull("b_calcfCode","反向计算编码")){
        return false;
    }
    var calcfCodeOld=$("#b_calcfCodeOld").val();
    var calcfCode=$("#b_calcfCode").val();
    if(calcfCodeOld==calcfCode){

    }else{

            var args={};
            args.c_calcfCode_1=$("#b_calcfCode").val();
            args.page=0;
            args.pageSize=5;
            args.isPage=1;


            var exists;
            $$.ajax({
                url: "/bootstrap/basegrid/IotCalcfDirectionBusiness/list",
                async:false,
                data: args,
                success: function (data) {
                    if(data.length && data.length>0){
                        exists=true;
                     }else{
                        exists=false;
                    }
                }
            });
            if(exists){
               $$.alert("反向计算编码已经存在,请重新输入!",function(index){
                   layer.close(index);
                   $("#b_calcfCode").focus();
               });
               return false;
             }

    }
    */

}

function addData() {
    var param = {};
    var validFormRet;
    $$.form({
        async: false,
        able: function () {
            validFormRet = false;
        },
        checkForm: validForm,
        success: function () {
            validFormRet = true;
        }
    });
    return validFormRet;
}

function forwardCalcValid() {
    $("#theform").validate({
        rules: {
            b_ttable: {

                required: true,

                minlength: 1,

                number: false

            },

            b_tcode: {

                required: true,

                minlength: 1,

                number: false

            },

            b_stable: {

                required: true,

                minlength: 1,

                number: false

            },

            b_scode: {

                required: true,

                minlength: 1,

                number: false

            },

            b_calcStart: {

                required: true,

                minlength: 1,

                number: false

            },

            b_calcEnd: {

                required: true,

                minlength: 1,

                number: false

            },

            b_status: {

                required: true,

                minlength: 1,

                number: false

            },

            b_rowSort: {

                required: true,

                minlength: 1,

                number: false

            }
        },
        errorPlacement: function (error, element) {
            error.appendTo(element.parent());
        },
        errorElement: "span",
        errorClass: "errortips",
        success: 'valid',
        messages: {
            b_ttable: {

                required: " (必填字段)",

                minlength: " (不能少于 1 个字母)",

                number: "请输入数字",

            },

            b_tcode: {

                required: " (必填字段)",

                minlength: " (不能少于 1 个字母)",

                number: "请输入数字",

            },

            b_stable: {

                required: " (必填字段)",

                minlength: " (不能少于 1 个字母)",

                number: "请输入数字",

            },

            b_scode: {

                required: " (必填字段)",

                minlength: " (不能少于 1 个字母)",

                number: "请输入数字",

            },

            b_calcStart: {

                required: " (必填字段)",

                minlength: " (不能少于 1 个字母)",

                number: "请输入数字",

            },

            b_calcEnd: {

                required: " (必填字段)",

                minlength: " (不能少于 1 个字母)",

                number: "请输入数字",

            },

            b_status: {

                required: " (必填字段)",

                minlength: " (不能少于 1 个字母)",

                number: "请输入数字",

            },

            b_rowSort: {

                required: " (必填字段)",

                minlength: " (不能少于 1 个字母)",

                number: "请输入数字",

            }
        },
    });
}

$(function () {
    forwardCalcValid();
    $("input[name^='b_status']").click(function () {
        $("#b_status").val($(this).val());
    });
});
